# -*- coding: utf-8 -*-

#    Copyright (C) 2014 by Promotux
#                       di Francesco Meloni snc - http://www.promotux.it/

#    Author: Francesco Meloni  <francesco@promotux.it>

#    This file is part of OdCollect.

#    OdCollect is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 2 of the License, or
#    (at your option) any later version.

#    OdCollect is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with OdCollect.  If not, see <http://www.gnu.org/licenses/>.

from sqlalchemy import Table
from sqlalchemy.orm import mapper, relation
from Environment import *
from lib.alembic.migration import MigrationContext
from lib.alembic.operations import Operations
from lib.alembic import op
from dao.Ente import Ente
from dao.DaoUtils import get_columns

try:
    t_sessione = Table('sessione', meta,
                        schema=mainSchema, autoload=True)
except:
    from data.sessione import t_sessione

from dao.Dao import Dao

class Sessione(Dao):

    def __init__(self, req=None):
        Dao.__init__(self, entity=self)

    def filter_values(self, k, v):
        if k == 'hash_sessione':
            dic = {k: t_sessione.c.hash_sessione == v}
        elif k == "codice":
            dic = {k: t_sessione.c.codice == v}
        elif k == "idTipo":
            dic = {k: t_sessione.c.id_tipo == v}
        return  dic[k]

    #@property
    #def tipo_ente(self):
        #if self.tipo_entee:
            #return self.tipo_entee.denominazione
        #else:
            #return None

std_mapper = mapper(Sessione, t_sessione, properties={
        'schema': relation(Ente, backref='ente')
            }, order_by=t_sessione.c.id)
